const { baseUrl } = require("./base.config.js");

module.exports = {
  parallel: false,
  lintOnSave: false,
  productionSourceMap: false,
  chainWebpack: (wpConfig) => {
    // 测试环境对组件进行测试
    if (process.env.VUE_APP_MODE == "dev") {
      wpConfig.plugin("html").tap((args) => {
        args[0].title = "lcd-component-xxx";
        return args;
      });
    }
  },
  configureWebpack: (wpConfig) => {
    // 删除vue-cli已有的images配置
    wpConfig.module.rules.splice(2, 1);
    // 区分src下使用url-loader和file-loader
    wpConfig.module.rules.push(
      // src的图片全部转化为base64
      {
        test: /\.(png|jpe?g|gif|webp)(\?.*)?$/,
        include: path.resolve(__dirname, "src"),
        use: [
          {
            loader: "url-loader",
            options: {
              esModule: false
            }
          }
        ],
      },
      // 非src下全部使用图片地址
      {
        test: /\.(png|jpe?g|gif|webp)(\?.*)?$/,
        exclude: path.resolve(__dirname, "src"),
        use: [
          {
            loader: "file-loader",
            options: {
              name: "img/[name].[hash:8].[ext]",
            },
          },
        ],
      }
    );
  },
  css: {
    loaderOptions: {
      // 向 CSS 相关的 loader 传递选项
      less: {},
    },
  },
  devServer: {
    port: 8888,
    // 反向代理配置
    proxy: {
      ["^/" + baseUrl]: {
        // 后台接口域名 联调更改此处IP即可
        target: "http://localhost:4000",
        pathRewrite: {
          ["^/" + baseUrl]: "",
        },
      }
    },
  },
};
